import { http } from '@/utils/http'
import type { PageResult } from '@/types/global'
import type { MedicineDetail, MedicineItem } from '@/types/medicine'

const url = '/medicine/medicine'

export const getMedicines = () => {
  return http<PageResult<MedicineItem>>({
    method: 'GET',
    url: `${url}/listWithCover`
  })
}

export const getMedicineDetail = (id: number) => {
  return http<MedicineDetail>({
    method: 'GET',
    url: `${url}/${id}`
  })
}

export const saveMedicine = (medicine: MedicineDetail) => {
  return http({
    method: 'POST',
    data: medicine,
    url
  })
}

export const updateMedicine = (medicine: MedicineDetail) => {
  return http({
    method: 'PUT',
    data: medicine,
    url
  })
}

export const deleteMedicine = (ids: number[]) => {
  return http({
    method: 'DELETE',
    data: ids,
    url
  })
}

export const deleteOssImg = (url: string) => {
  return http({
    method: 'DELETE',
    url: '/medicine/oss/delete?url=' + url
  })
}
